var express = require('express');
const UserModel = require('../model/UserModel');
const UserController = require('../controllers/UserController')

//multer用来处理表单中的 enctype="multipart/form-data" 数据
const multer  = require('multer')
const upload = multer({ dest: 'public/uploads/' })  //上传文件的保存路径

var router = express.Router();

/**
 * 
 * @api {post} /api/user 添加用户
 * @apiName addUser
 * @apiGroup usergroup
 * @apiVersion  1.0.0
 * 
 * 
 * @apibody  {String} username  用户名
 * @apibody  {String} password  密码
 * @apibody  {number} age 年龄
 * @apibody  {String} avatar 头像
 * 
 * @apiSuccess (200) {number} ok 标识成功字段
 * 
 * @apiParamExample  {type} Request-Example:
 * {
 *     username: 'yun',
 *     password: '123'
 *     age: 100,
 *     avatar: File
 * }
 * 
 * 
 * @apiSuccessExample {type} Success-Response:
 * {
 *     ok: 1
 * }
 * 
 * 
 */


/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

//添加数据
router.post('/user',upload.single("avatar"),UserController.addUser)

//更新数据
//动态路由,req.params获取id
router.put('/user/:id',UserController.updateUser)
//删除数据
router.delete('/user/:id',UserController.deleteUser)
//获取数据
console.log('获取数据')
router.get("/user/list",UserController.findUser)


//登录校验
router.post("/login",UserController.login)
//退出登录
router.get('/logout',UserController.logout)

module.exports = router;
